convert part 2
bits_to_int
include convert.e namespace convert public function bits_to_int(sequence bits)
converts a sequence of bits to an atom that has no fractional part.
Parameters:
- bits : the sequence to convert.
Returns:
A positive atom, whose machine representation was given by bits.
Comments:
An element in bits can be any atom. If nonzero, it counts for 1, else for 0.
The first elements in bits represent the bits with the least weight in the returned value. Only the 52 last bits will matter, as the PC hardware cannot hold an integer with more digits than this.
If you print s the bits will appear in "reverse" order, but it is convenient to have increasing subscripts access bits of increasing significance.
Example 1:
a = bits_to_int({1,1,1,0,1}) -- a is 23 (binary 10111)
See Also:
bytes_to_int, int_to_bits, operations on sequences
atom_to_float64
include convert.e namespace convert public function atom_to_float64(atom a)
converts an atom to a sequence of 8 bytes in IEEE 64-bit format.
Parameters:
- a : the atom to convert:
Returns:
A sequence, of 8 bytes, which can be poked in memory to represent a.
Comments:
All Euphoria atoms have values which can be represented as 64-bit IEEE floating-point numbers, so you can convert any atom to 64-bit format without losing any precision.
Integer values will also be converted to 64-bit floating-point format.
Example 1:
fn = open("numbers.dat", "wb") puts(fn, atom_to_float64(157.82)) -- write 8 bytes to a file
See Also:
Not Categorized, Please Help
|